package com.example.helloworld;

import java.util.ArrayList;
import java.util.Iterator;

public class IteratorTest {
    public static void main(String[] args) {
        // 创建集合
        ArrayList<String> list = new ArrayList<>();
        list.add("apple");
        list.add("banana");
        list.add("orange");

        Iterator<String> iterator = list.iterator();
        System.out.println(iterator.next());

        while (iterator.hasNext()) {
            System.out.println(iterator.next());
            String element = iterator.next();
            if (element.equals("banana")) {
                iterator.remove();
            }

        }

        System.out.println(list);

    }
}
